package com.wwtech.epp.ui.adapter.work;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.ProjectEntity;
import com.wwtech.epp.utils.WorkUtil;

import java.util.List;

/**
 * 作者：Android on 2017/9/15
 * 邮箱：365941593@qq.com
 * 描述：
 */

public class ProjectListAdapter extends BaseQuickAdapter<ProjectEntity.DataBean.ListBean, BaseViewHolder> {
    public String ProjectType = "";

    public String getProjectType() {
        return ProjectType;
    }

    public void setProjectType(String projectType) {
        ProjectType = projectType;
    }

    public ProjectListAdapter(@Nullable List<ProjectEntity.DataBean.ListBean> data) {
        super(R.layout.project_list_item, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ProjectEntity.DataBean.ListBean projectEntity) {
        if (projectEntity.getProjectId() == 0) {
            return;
        }
        baseViewHolder.setVisible(R.id.work_star, projectEntity.isStar()? true : false);
        if (ProjectType.equals("我的项目")) {
            baseViewHolder.setText(R.id.fuzeren, "负责人:");
        } else {
            baseViewHolder.setText(R.id.fuzeren, "负责人:");
        }
        baseViewHolder.setText(R.id.title, projectEntity.getProjectName())
                .setText(R.id.tv_content, projectEntity.getProjectDesc())
                .setText(R.id.name, projectEntity.getNickName())
                .setText(R.id.tv_time, "截止时间:" + projectEntity.getEndTime().substring(0, 11));
        TextView state = baseViewHolder.getView(R.id.tv_jindu);
        if (WorkUtil.isUnValuableTask(projectEntity.getEndTime()) == -1 || projectEntity.getProjectState() == 1 || WorkUtil.isUnValuableTask(projectEntity.getEndTime()) == 0) {
            switch (projectEntity.getProjectState()) {
                case 0:
                    state.setText("进度正常");
                    state.setTextColor(mContext.getResources().getColor(R.color.main_color));
                    break;
                case 1:
                    state.setText("已结束");
                    state.setTextColor(mContext.getResources().getColor(R.color.color_finish_task));
                    break;
                default:
                    break;
            }
        } else {
            state.setText("超期" + WorkUtil.isUnValuableTask(projectEntity.getEndTime()) + "天");
            state.setTextColor(mContext.getResources().getColor(R.color.color_f51818));
        }
    }
}
